package com.onesports.intelligent.k12.polarlight.controller.operation;

import cn.oneframework.common.utils.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.EditStatusDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.IdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.ResetAccountPwdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.InsertOrganizationDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.PageOrganizationDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.operation.UpdOrganizationDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.operation.PageOrganizationVO;
import com.onesports.intelligent.k12.polarlight.service.operation.OrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author wangcx
 * @since 2022-7-8
 */
@Api(value = "运营团队", tags = "运营端-运营团队管理")
@RestController
@RequestMapping(ApiPathConstants.OPERATION_ORGANIZATION)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class OrganizationController {

    private final OrganizationService service;

    @PostMapping("/add")
    @ApiOperation(value = "新增运营团队")
    public ResponseEntity add(@Valid @RequestBody InsertOrganizationDTO dto)
    {
        service.add(dto);
        return ResultUtil.success("添加成功");
    }


    @PostMapping("/upd")
    @ApiOperation(value = "修改运营团队")
    public ResponseEntity upd(@Valid @RequestBody UpdOrganizationDTO dto)
    {
        service.upd(dto);
        return ResultUtil.success("修改成功");
    }

    @PostMapping("/reset-pwd")
    @ApiOperation(value = "重置密码")
    public ResponseEntity resetPwd(@Valid @RequestBody ResetAccountPwdDTO dto)
    {
        service.resetAccountPwd(dto);
        return ResultUtil.success("密码重置成功");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除运营团队")
    public ResponseEntity del(@Valid @RequestBody IdDTO dto)
    {
        service.del(dto.getId());
        return ResultUtil.success("删除成功");
    }


    @PostMapping("/upd-status")
    @ApiOperation(value = "启用禁用运营团队")
    public ResponseEntity updStatus(@Valid @RequestBody EditStatusDTO dto)
    {
        service.updStatus(dto);
        return ResultUtil.success("修改成功");
    }


    @PostMapping("/page")
    @ApiOperation(value = "分页查询运营团队列表", response = PageOrganizationVO.class)
    public ResponseEntity<IPage<PageOrganizationVO>> findPage(@Valid @RequestBody PageOrganizationDTO dto) {
        return ResultUtil.success(this.service.findPage(new Page<>(dto.getPage(),dto.getRow()),dto));

    }


}